package com.iyundao.io.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.iyundao.io.Service.ImageService;
import com.iyundao.io.model.ActivityImage;
import com.iyundao.io.model.GiftImage;
import com.iyundao.io.model.SignInImage;
import com.iyundao.io.tools.ResponseData;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping(value = "/image")
@RestController
public class ImageController {

    @Autowired
    private ImageService imageService;

    @ApiOperation(value="活动图片上传", notes="活动图片上传")
    @RequestMapping(value = "/addactivityimage", produces = {"application/json;charset=UTF-8"})
    @CrossOrigin
    public ResponseData ActivityImageInsert(@RequestBody String params){
        JSONObject object = JSONObject.parseObject(params);
        Integer activityId = (Integer) object.get("activityId");
        String activityImageUrl = (String) object.get("activityImageUrl");
        ActivityImage activityImage = new ActivityImage();
        activityImage.setActivityimageurl(activityImageUrl);
        activityImage.setActivityid(activityId);
        return imageService.activityImageInsert(activityImage);
    }

    @ApiOperation(value="签到图片上传", notes="签到图片上传")
    @RequestMapping(value = "/addsigninimage", produces = {"application/json;charset=UTF-8"})
    @CrossOrigin
    public ResponseData SignInImageInsert(@RequestBody JSONObject params){
        SignInImage signInImage = JSON.toJavaObject(params, SignInImage.class);
        return imageService.signInImageInsert(signInImage);
    }

    @ApiOperation(value="礼品图片上传", notes="礼品图片上传")
    @RequestMapping(value = "/addgiftimage", produces = {"application/json;charset=UTF-8"})
    @CrossOrigin
    public ResponseData GiftImageInsert(@RequestBody JSONObject params){
        GiftImage giftImage = JSON.toJavaObject(params, GiftImage.class);
        return imageService.giftImageInsert(giftImage);
    }

}
